package servlet;

import dao.AdminsDao;
import dao.MessagesDao;
import dao.UsersDao;
import dao.impl.AdminsDaoImpl;
import dao.impl.MessagesDaoImpl;
import dao.impl.UsersDaoImpl;
import entity.Users;
import entity.vo.DoctorsGetAppointments;
import entity.vo.MessageData;
import utils.ResponseResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "AdminMessageServlet", urlPatterns = "/bigProjects/AdminMessageServlet")

public class AdminMessageServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AdminsDao adminsDao = new AdminsDaoImpl();
        // 设置响应的内容类型为 JSON
        resp.setContentType("application/json");
        //设置ContentType字段值
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        List<DoctorsGetAppointments> doctorsGetAppointments = adminsDao.queryAllAppointments();
        resp.getWriter().write(ResponseResult.success(doctorsGetAppointments).toString());
    }

    //管理员获取留言信息
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MessagesDao messagesDao = new MessagesDaoImpl();
        // 设置响应的内容类型为 JSON
        resp.setContentType("application/json");
        //设置ContentType字段值
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        List<MessageData> messageData = messagesDao.selectPrivateMessagePage();
        resp.getWriter().write(ResponseResult.success(messageData).toString());
    }

    //管理员获取所有用户信息
    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UsersDao usersDao = new UsersDaoImpl();
        // 设置响应的内容类型为 JSON
        resp.setContentType("application/json");
        //设置ContentType字段值
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        List<Users> usersData = usersDao.getAllUsers();
        resp.getWriter().write(ResponseResult.success(usersData).toString());
    }

}
